package edu.bit.water.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.bit.water.entity.LabelEvaEntPrdInfo;
import edu.bit.water.service.LabelEvaEntPrdInfoService;

@Controller
@RequestMapping("/label_eva_ent_prd_info")
public class LabelEvaEntPrdInfoController {

	@Autowired
	private LabelEvaEntPrdInfoService labelEvaEntPrdInfoService;
	
	/**
	 * 查询标签表中的记录
	 * @return 标签表中的所有记录
	 */
	@RequestMapping("/select")
	@ResponseBody
	public Map<String, Object> select(){
		Map<String, Object> modelMap = new HashMap<>();
	    List<LabelEvaEntPrdInfo> list = labelEvaEntPrdInfoService.select();
	    modelMap.put("status", "success");
	    modelMap.put("rows", list);
		return modelMap;
	}
	/**
	 * @param labelEvaEntPrdInfo 标签记录实体
	 * @return 成功返回1,失败返回0	 
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public Map<String, String> insert(LabelEvaEntPrdInfo labelEvaEntPrdInfo){
		return labelEvaEntPrdInfoService.insert(labelEvaEntPrdInfo);
	}
	/**
	 * 更新记录
	 * @param labelEvaEntPrdInfo 标签记录实体
	 * @return 成功返回1,失败返回0	 
	 */
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, String> update( LabelEvaEntPrdInfo labelEvaEntPrdInfo){
		return labelEvaEntPrdInfoService.update(labelEvaEntPrdInfo);	
	}
	/**
	 * 删除记录
	 * @param id 删除记录的标识符
	 * @return 成功返回1,失败返回0	 
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestBody List<Integer> ids){
		Map<String, Object> modelMap = new HashMap<>();
	    int n = labelEvaEntPrdInfoService.delete(ids);
	    if(n == 1) {
	    	modelMap.put("status", "success");
	    }
	    else
	    	modelMap.put("status", "failed");
		return modelMap;
	}
}
